package com.lzq.badminton.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lzq.badminton.dto.OrderDto;
import com.lzq.badminton.dto.OrderPageDto;
import com.lzq.badminton.dto.PayDto;
import com.lzq.badminton.entity.Order;
import com.lzq.badminton.service.OrderService;
import com.lzq.badminton.utils.SecurityUtils;
import com.lzq.badminton.vo.OrderPaymentVO;
import com.lzq.badminton.vo.OrderVo;
import com.lzq.badminton.vo.ResponseResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")

public class OrderController {


    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    @ApiOperation(value="创建订单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", required = true),
    })
    public ResponseResult createOrder(@RequestBody OrderDto orderDto){
        ResponseResult responseResult = orderService.addOrder(orderDto);
        return responseResult;
    }

    @PostMapping("/list")
    public ResponseResult listOrder(@RequestBody OrderPageDto orderPageDto){
        Integer pageNum = orderPageDto.getPageNum();
        Integer pageSize = orderPageDto.getPageSize();
        Integer status = orderPageDto.getStatus();
        List<OrderVo> orderVoList = orderService.listOrderByUser(pageNum, pageSize, status);
        return ResponseResult.okResult(orderVoList);
    }

    @PostMapping("/pay")
    @ApiOperation(value = "支付订单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", required = true),
    })
    public ResponseResult payOrder(@RequestBody PayDto payDto) throws Exception {
        OrderPaymentVO orderPaymentVO = orderService.payOrder(payDto);
        return ResponseResult.okResult(orderPaymentVO);
    }

    /**
     * 用户取消订单
     */
    @GetMapping ("/refund/{id}")
    @ApiOperation("退款取消")
    public ResponseResult refund(@PathVariable("id") Long id) throws Exception {
        orderService.userCancelById(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/cancle/{id}")
    public ResponseResult cancel(@PathVariable("id") Long id) throws Exception {
        orderService.cancleNoRefund(id);
        return ResponseResult.okResult();
    }
}





